home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / Xsun / sunBW2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-07  |  8.9 KB  |  335 lines

  1. /*-
  2.  * sunBW2.c --
  3.  *    Functions for handling the sun BWTWO board.
  4.  *
  5.  * Copyright (c) 1987 by the Regents of the University of California
  6.  * Copyright (c) 1987 by Adam de Boor, UC Berkeley
  7.  *
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  *
  16.  *
  17.  */
  18.  
  19. /************************************************************
  20. Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
  21.  
  22.                     All Rights Reserved
  23.  
  24. Permission  to  use,  copy,  modify,  and  distribute   this
  25. software  and  its documentation for any purpose and without
  26. fee is hereby granted, provided that the above copyright no-
  27. tice  appear  in all copies and that both that copyright no-
  28. tice and this permission notice appear in  supporting  docu-
  29. mentation,  and  that the names of Sun or MIT not be used in
  30. advertising or publicity pertaining to distribution  of  the
  31. software  without specific prior written permission. Sun and
  32. M.I.T. make no representations about the suitability of this
  33. software for any purpose. It is provided "as is" without any
  34. express or implied warranty.
  35.  
  36. SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
  37. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
  38. NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
  39. ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  40. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
  41. PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
  42. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
  43. THE USE OR PERFORMANCE OF THIS SOFTWARE.
  44.  
  45. ********************************************************/
  46.  
  47.  
  48. #ifndef    lint
  49. static char sccsid[] = "%W %G Copyright 1987 Sun Micro";
  50. #endif
  51.  
  52. /*-
  53.  * Copyright (c) 1987 by Sun Microsystems,  Inc.
  54.  */
  55.  
  56. #include    "sun.h"
  57. #include    "resource.h"
  58. #include "sys/fb.h"
  59. #include "sys/ioctl.h"
  60. #include "kernel/vmMach.h"
  61. #include "sys/types.h"
  62.  
  63. extern caddr_t mmap();
  64.  
  65. #include    <sys/mman.h>
  66. #ifdef sprite
  67. #undef _MAP_NEW
  68. #endif
  69.  
  70. #ifndef    sprite
  71. #include    <sundev/bw2reg.h>
  72.  
  73.  
  74. typedef struct bw2 {
  75.     u_char    image[BW2_FBSIZE];          /* Pixel buffer */
  76. } BW2, BW2Rec, *BW2Ptr;
  77.  
  78. typedef struct bw2hr {
  79.     u_char    image[BW2_FBSIZE_HIRES];          /* Pixel buffer */
  80. } BW2HR, BW2HRRec, *BW2HRPtr;
  81. #endif    sprite
  82.  
  83. static int  sunBW2ScreenIndex;
  84.  
  85. /*-
  86.  *-----------------------------------------------------------------------
  87.  * sunBW2SaveScreen --
  88.  *    Disable the video on the frame buffer to save the screen.
  89.  *
  90.  * Results:
  91.  *    None.
  92.  *
  93.  * Side Effects:
  94.  *    Video enable state changes.
  95.  *
  96.  *-----------------------------------------------------------------------
  97.  */
  98. static Bool
  99. sunBW2SaveScreen (pScreen, on)
  100.     ScreenPtr      pScreen;
  101.     Bool          on;
  102. {
  103.     int         state = on;
  104.  
  105.     if (on != SCREEN_SAVER_ON) {
  106.     SetTimeSinceLastInputEvent();
  107.     state = FBVIDEO_ON;
  108.     } else {
  109.     state = FBVIDEO_OFF;
  110.     }
  111.     (void) ioctl(sunFbs[pScreen->myNum].fd, FBIOSVIDEO, &state);
  112.     return TRUE;
  113. }
  114.  
  115. /*-
  116.  *-----------------------------------------------------------------------
  117.  * sunBW2CloseScreen --
  118.  *    called to ensure video is enabled when server exits.
  119.  *
  120.  * Results:
  121.  *    Screen is unsaved.
  122.  *
  123.  * Side Effects:
  124.  *    None
  125.  *
  126.  *-----------------------------------------------------------------------
  127.  */
  128. /*ARGSUSED*/
  129. static Bool
  130. sunBW2CloseScreen(i, pScreen)
  131.     int        i;
  132.     ScreenPtr    pScreen;
  133. {
  134.     Bool    ret;
  135.  
  136.     pScreen->CloseScreen = (Bool (*)()) pScreen->devPrivates[sunBW2ScreenIndex].ptr;
  137.     ret = (*pScreen->CloseScreen) (i, pScreen);
  138.     (void) (*pScreen->SaveScreen) (pScreen, SCREEN_SAVER_OFF);
  139.     return ret;
  140. }
  141.  
  142. /*-
  143.  *-----------------------------------------------------------------------
  144.  * sunBW2Init --
  145.  *    Attempt to find and initialize a bw2 framebuffer
  146.  *
  147.  * Results:
  148.  *    None
  149.  *
  150.  * Side Effects:
  151.  *    Most of the elements of the ScreenRec are filled in.  The
  152.  *    video is enabled for the frame buffer...
  153.  *
  154.  *-----------------------------------------------------------------------
  155.  */
  156. /*ARGSUSED*/
  157. static Bool
  158. sunBW2Init (index, pScreen, argc, argv)
  159.     int              index;        /* The index of pScreen in the ScreenInfo */
  160.     ScreenPtr      pScreen;      /* The Screen to initialize */
  161.     int              argc;            /* The number of the Server's arguments. */
  162.     char          **argv;       /* The arguments themselves. Don't change! */
  163. {
  164.     if (!mfbScreenInit(pScreen,
  165.                sunFbs[index].fb,
  166.                sunFbs[index].info.fb_width,
  167.                sunFbs[index].info.fb_height,
  168.                monitorResolution, monitorResolution,
  169.                sunFbs[index].info.fb_width))
  170.     return (FALSE);
  171.  
  172.     pScreen->devPrivates[sunBW2ScreenIndex].ptr = (pointer) pScreen->CloseScreen;
  173.     pScreen->CloseScreen = sunBW2CloseScreen;
  174.     pScreen->SaveScreen = sunBW2SaveScreen;
  175.     pScreen->whitePixel = 0;
  176.     pScreen->blackPixel = 1;
  177.  
  178.     /*
  179.      * Enable video output...? 
  180.      */
  181.     (void) sunBW2SaveScreen(pScreen, SCREEN_SAVER_FORCER);
  182.  
  183.     return (sunScreenInit(pScreen) && mfbCreateDefColormap(pScreen));
  184. }
  185.  
  186. /*-
  187.  *-----------------------------------------------------------------------
  188.  * sunBW2Probe --
  189.  *    Attempt to find and initialize a bw2 framebuffer
  190.  *
  191.  * Results:
  192.  *    None
  193.  *
  194.  * Side Effects:
  195.  *    Memory is allocated for the frame buffer and the buffer is mapped. 
  196.  *
  197.  *-----------------------------------------------------------------------
  198.  */
  199.  
  200. /*ARGSUSED*/
  201. Bool
  202. sunBW2Probe(pScreenInfo, index, fbNum, argc, argv)
  203.     ScreenInfo      *pScreenInfo;    /* The screenInfo struct */
  204.     int              index;        /* The index of pScreen in the ScreenInfo */
  205.     int              fbNum;        /* Index into the sunFbData array */
  206.     int              argc;            /* The number of the Server's arguments. */
  207.     char          **argv;       /* The arguments themselves. Don't change! */
  208. {
  209. #ifdef    NOTDEF
  210.     fbtype    fbt;
  211.     fbaddr    fba;
  212.     pointer    buffer;
  213.  
  214.     if(Fb_GTYPE(&fbt) != SUCCESS) {
  215.         return FALSE;
  216.     }
  217.     switch(fbt.fb_type) {
  218.     case FBTYPE_SUN2BW:
  219.         if(Fb_MAP(&fba) != SUCCESS) {
  220.             return FALSE;
  221.         }
  222.         buffer = fba.fb_buffer;
  223.         break;
  224.     case FBTYPE_SUN4COLOR:
  225.         if(Fb_MAP(&fba) != SUCCESS) {
  226.             return FALSE;
  227.         }
  228.         buffer = fba.fb_overlay;
  229.         /* fudge */
  230.         fbt.fb_type = FBTYPE_SUN2BW;
  231.         fbt.fb_depth = 1;
  232.         fbt.fb_cmsize = 2;
  233.         fbt.fb_size = 128*1024;
  234.         break;
  235.     default:
  236.         return FALSE;
  237.     }
  238. #endif NOTDEF
  239.  
  240.     int         fd;
  241.     struct fbtype fbType;
  242.     int        pagemask, mapsize;
  243.     caddr_t    addr, mapaddr;
  244. #ifdef sprite
  245.     int        sizeToUse;
  246. #endif /* sprite */
  247.  
  248.     if ((fd = sunOpenFrameBuffer(FBTYPE_SUN2BW, &fbType, index, fbNum,
  249.                  argc, argv)) < 0)
  250.     return FALSE;
  251.  
  252.     /*
  253.      * It's not precisely clear that we have to round up
  254.      * fb_size to the nearest page boundary but there are
  255.      * rumors that this is a good idea and that it shouldn't
  256.      * hurt anything.
  257.      */
  258.     pagemask = getpagesize() - 1;
  259.     mapsize = (fbType.fb_size + pagemask) & ~pagemask;
  260.     addr = 0;
  261.  
  262. #ifndef _MAP_NEW
  263.     /*
  264.      * If we are running pre-SunOS 4.0 then we first need to
  265.      * allocate some address range for mmap() to replace.
  266.      */
  267. #ifdef sprite
  268.     sizeToUse = ((mapsize + VMMACH_SEG_SIZE) & ~(VMMACH_SEG_SIZE-1))
  269.         + VMMACH_SEG_SIZE;
  270.     addr = (caddr_t) malloc(sizeToUse);
  271.     if (addr == NULL) {
  272. #else
  273.     if ((addr = (caddr_t) valloc(mapsize)) == 0) {
  274. #endif /* sprite */
  275.         ErrorF("Could not allocate room for frame buffer.\n");
  276.         (void) close(fd);
  277.         return FALSE;
  278.     }
  279. #endif _MAP_NEW
  280.  
  281. #ifdef sprite
  282.     addr = (caddr_t) mmap((caddr_t) addr, mapsize,
  283.         PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t)0);
  284.     if (addr == (caddr_t) NULL) {
  285. #else
  286.     /*
  287.      * In SunOS 4.0 the standard C library mmap() system call
  288.      * wrapper will automatically add a _MAP_NEW flag for us.
  289.      * In pre-4.0 mmap(), success returned 0 but now it returns the
  290.      * newly mapped starting address. The test for mapaddr
  291.      * being 0 below will handle this difference correctly.
  292.      */
  293.     if ((mapaddr = (caddr_t) mmap(addr, mapsize,
  294.         PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t)0)) == (caddr_t) -1) {
  295. #endif /* sprite */
  296.         Error("mapping BW2");
  297.         (void) close(fd);
  298.         return FALSE;
  299.     }
  300.  
  301. #ifndef sprite
  302.     if (mapaddr == 0)
  303.         mapaddr = addr;
  304. #endif /* sprite */
  305.  
  306. #ifdef sprite
  307.     sunFbs[index].fb = (pointer) addr;
  308.     /*
  309.      * XXX What do we do here about fudging the FBTYPE_SUN4COLOR to be
  310.      * black and white (as in the notdef'ed section above).?
  311.      */
  312. #else
  313.     sunFbs[index].fb = buffer;
  314. #endif /* sprite */
  315.     sunFbs[index].info = fbType;
  316.     sunFbs[index].EnterLeave = NULL;
  317.     sunFbs[index].fd = fd;
  318.     return TRUE;
  319. }
  320.  
  321. Bool
  322. sunBW2Create(pScreenInfo, argc, argv)
  323.     ScreenInfo      *pScreenInfo;
  324.     int              argc;
  325.     char          **argv;
  326. {
  327.     if (sunGeneration != serverGeneration)
  328.     {
  329.     sunBW2ScreenIndex = AllocateScreenPrivateIndex();
  330.     if (sunBW2ScreenIndex < 0)
  331.         return FALSE;
  332.     }
  333.     return (AddScreen(sunBW2Init, argc, argv) >= 0);
  334. }
  335.